/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#include "MuRo_QuestionFrame.h"
#include "AlarmBalloon.hpp"

MuRo_QuestionFrame::MuRo_QuestionFrame( wxWindow* parent, MuRo::CAlarmBalloon* alarmBalloon)
:
_QuestionFrame( parent ),
alarmBalloon(alarmBalloon)
{
  std::string header("Question: ");
  if (alarmBalloon->data.GetHeadingText())
    header.append(alarmBalloon->data.GetHeadingText()->text,
                alarmBalloon->data.GetHeadingText()->length);
  staticText_Header->SetLabel(header);
  
  std::string source("Source:");
  if (alarmBalloon->data.GetSourceNameText())
    source.append(alarmBalloon->data.GetSourceNameText()->text,
                alarmBalloon->data.GetSourceNameText()->length);
  staticText_Source->SetLabel(source);
  
  std::string message;
  if (alarmBalloon->data.GetText())
    message.append(alarmBalloon->data.GetText()->text,
                 alarmBalloon->data.GetText()->length);
  textCtrl_Message->SetValue(message);
}

void MuRo_QuestionFrame::OnClose( wxCloseEvent& event )
{
	// TODO: Implement OnClose
  alarmBalloon->Expand(false);
}

void MuRo_QuestionFrame::OnYes( wxCommandEvent& event )
{
	// TODO: Implement OnYes
  SendReply(MaCI::Alarm::KCommandUserQuestionReplyYes);
  alarmBalloon->Destroy();
}

void MuRo_QuestionFrame::OnNo( wxCommandEvent& event )
{
	// TODO: Implement OnNo
  SendReply(MaCI::Alarm::KCommandUserQuestionReplyNo);
  alarmBalloon->Destroy();
}

void MuRo_QuestionFrame::OnCloseButton( wxCommandEvent& event )
{
  alarmBalloon->Expand(false);
}

void MuRo_QuestionFrame::SendReply(MaCI::Alarm::EAlarmCommand cmd)
{
  MaCI::Alarm::CAlarmData d;
  d.CreateInternalBinBag();
  MaCI::Alarm::TCommand c;
  c.data=alarmBalloon->data.GetAlarmEvent()->id;
  c.cmd=cmd;
  d.SetCommand(c);
  if (!alarmBalloon->client->SendCommand(d))
    wxMessageBox("Failed to send reply!");
}
